﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using SNSpirit.Service.Access;
using SNSpirit.Service.Authentication;
using SNSpirit.Service.Identity;

namespace SNSpirit.Plugins.CC98.Authentication
{
    internal class CC98Identity : Identity<ulong>
    {
        public CC98Identity(ulong id, string username)
        {
            this.ID = id;
            this.Username = username;
        }
    }

    internal class AuthToken : AuthenticationToken
    {
        public static bool IsAuthenticated(CookieCollection cookies)
        {
            throw new NotImplementedException();
        }

        public static CC98Identity GetIdentity(CookieCollection cookies)
        {
            throw new NotImplementedException();
        }

        public AuthToken(NamePasswordAuthenticationConnector connector, CookieCollection cookies)
        {
            if (connector == null)
                throw new ArgumentNullException("connector");
            this._cookies = cookies;
            this._connector = connector;
            // init
            this.IsAnonymous = !(cookies != null && IsAuthenticated(cookies));
            // identity
            if (!this.IsAnonymous)
                this.Identity = GetIdentity(cookies);
        }

        public override IAccessor GetAccessor<T>()
        {
            if (typeof(T) == typeof(IWebAccessor))
            {
                return new WebAccessor(this._connector, this._cookies);
            }
            else
            {
                throw new NotSupportedException();
            }
        }

        private CookieCollection _cookies;

        private NamePasswordAuthenticationConnector _connector;
    }
}